package com.monitor.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.monitor.common.annotation.Log;
import com.monitor.common.core.controller.BaseController;
import com.monitor.common.core.domain.AjaxResult;
import com.monitor.common.enums.BusinessType;
import com.monitor.system.domain.SoftwareDevice;
import com.monitor.system.service.ISoftwareDeviceService;
import com.monitor.common.utils.poi.ExcelUtil;
import com.monitor.common.core.page.TableDataInfo;

/**
 * 软件设备Controller
 * 
 * @author monitor
 * @date 2024-06-13
 */
@RestController
@RequestMapping("/system/softwareDevice")
public class SoftwareDeviceController extends BaseController
{
    @Autowired
    private ISoftwareDeviceService softwareDeviceService;

    /**
     * 查询软件设备列表
     */
    @PreAuthorize("@ss.hasPermi('system:device:list')")
    @GetMapping("/list")
    public TableDataInfo list(SoftwareDevice softwareDevice)
    {
        startPage();
        List<SoftwareDevice> list = softwareDeviceService.selectSoftwareDeviceList(softwareDevice);
        return getDataTable(list);
    }

    /**
     * 导出软件设备列表
     */
    @PreAuthorize("@ss.hasPermi('system:device:export')")
    @Log(title = "软件设备", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SoftwareDevice softwareDevice)
    {
        List<SoftwareDevice> list = softwareDeviceService.selectSoftwareDeviceList(softwareDevice);
        ExcelUtil<SoftwareDevice> util = new ExcelUtil<SoftwareDevice>(SoftwareDevice.class);
        util.exportExcel(response, list, "软件设备数据");
    }

    /**
     * 获取软件设备详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:device:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(softwareDeviceService.selectSoftwareDeviceById(id));
    }

    /**
     * 新增软件设备
     */
    @PreAuthorize("@ss.hasPermi('system:device:add')")
    @Log(title = "软件设备", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SoftwareDevice softwareDevice)
    {
        return toAjax(softwareDeviceService.insertSoftwareDevice(softwareDevice));
    }

    /**
     * 修改软件设备
     */
    @PreAuthorize("@ss.hasPermi('system:device:edit')")
    @Log(title = "软件设备", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SoftwareDevice softwareDevice)
    {
        return toAjax(softwareDeviceService.updateSoftwareDevice(softwareDevice));
    }

    /**
     * 删除软件设备
     */
    @PreAuthorize("@ss.hasPermi('system:device:remove')")
    @Log(title = "软件设备", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(softwareDeviceService.deleteSoftwareDeviceByIds(ids));
    }
}
